package com.cea.papyrustest.uml.createcommand;

import java.util.List;

import org.eclipse.uml2.uml.InstanceSpecification;
import org.eclipse.uml2.uml.Slot;

import com.cea.papyrus.core.commands.UMLElementCreateCommand;

/**
 * Test class for {@link Slot} creation command
 * @author Remi Schnekenburger
 */
public class SlotCreateCommandTest extends PapyrusCommandTest{

	/** name of the created element */
	protected final String NAME = "<slot>0"; 
	
	protected InstanceSpecification instanceSpecification;
	
	/**
	 * Default constructor
	 * @param name the name oif the test case
	 */
	public SlotCreateCommandTest(String name) {
		super(name);	
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		
		papyrusCommand= new UMLElementCreateCommand(org.eclipse.uml2.uml.InstanceSpecification.class,model);
		stack.execute(papyrusCommand);
		// Class_0 is created!
		instanceSpecification=(InstanceSpecification)((UMLElementCreateCommand)papyrusCommand).getElement();
		
		papyrusCommand= new UMLElementCreateCommand(org.eclipse.uml2.uml.Slot.class,instanceSpecification);
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrustest.PapyrusCommandTest#testExecute()
	 */
	@Override
	public void testExecute() {
		stack.execute(papyrusCommand);
		List<Slot> slots = instanceSpecification.getSlots();
		assertNotNull("the slot is not created", slots);
		assertEquals("There should be one slot in this list", 1, slots.size());
		assertTrue("this is not a slot", (slots.get(0) instanceof Slot));
		
		// undo
		stack.undo();
		slots = instanceSpecification.getSlots();
		assertNotNull("the slot is not deleted", slots);
		assertEquals("There should be no slots in this list", 0, slots.size());
		
		// redo
		stack.redo();
		slots = instanceSpecification.getSlots();
		assertNotNull("the slot is not created", slots);
		assertEquals("There should be one slot in this list", 1, slots.size());
		assertTrue("this is not a slot", (slots.get(0) instanceof Slot));
	}
}
